# author = '李天宝'
# write in '2020/8/5 0005 15:51'


from django.contrib.auth.backends import ModelBackend
from django.db.models import Q
from LoginSign.models import User
# 记得引入用户的model
class CustomBackend(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):
        try:
            print("fuck fuck fuck")
            user = User.objects.filter(Q(username=username) | Q(telephone=username)).first()

            if user.check_password(password):
                print("密码验证成功")
                return user

            #刚开始创建的那些用户没得hash密码，只能够加上这一条验证规则了
            if user.password==password:
                return user

        except Exception as e:
            return None